<?php
/**
 * EasySEF - SEF component for Joostina CMS.
 * @author:      Лаборатория сайтов, http://sitelab.net.ru
 * @version:     1.1
 * @release:     2010.01.07
 * @package:     com_sef
 * @copyright:   (C) 2010 http://sitelab.net.ru, , see /administrator/components/com_sef/copyright.php
 * @license:     http://www.gnu.org/copyleft/gpl.html GNU/GPL
 *
 * Cоздан на базе sh404SEF  (C) 2007 by Yannick Gaultier
 *
 * easysef support for com_XXXXX component.
 * Author :
 * contact :
 *
 * {shSourceVersionTag: Version x - 2007-09-20}
 *
 * This is a sample easysef native plugin file
 *
 */
defined( '_VALID_MOS' ) or die();

// ------------------  standard plugin initialize function - don't change ---------------------------
global $sh_LANG, $sefConfig;  
$shLangName = '';
$shLangIso = '';
$title = array();
$shItemidString = '';
$dosef = shInitializePlugin( $lang, $shLangName, $shLangIso, $option);
if ($dosef == false) return;
// ------------------  standard plugin initialize function - don't change ---------------------------

// ------------------  load language file - adjust as needed ----------------------------------------
//$shLangIso = shLoadPluginLanguage( 'com_XXXXX', $shLangIso, '_SEF_SAMPLE_TEXT_STRING');
// ------------------  load language file - adjust as needed ----------------------------------------

// remove common URL from GET vars list, so that they don't show up as query string in the URL
shRemoveFromGETVarsList('option');
shRemoveFromGETVarsList('lang');
if (!empty($Itemid))
	shRemoveFromGETVarsList('Itemid');
if (!empty($limit))  
	shRemoveFromGETVarsList('limit');
if (isset($limitstart)) 
	shRemoveFromGETVarsList('limitstart'); // limitstart can be zero


// start by inserting the menu element title (just an idea, this is not required at all)
$task = isset($task) ? @$task : null;
$Itemid = isset($Itemid) ? @$Itemid : null;
$shSampleName = shGetComponentPrefix($option); 
$shSampleName = empty($shSampleName) ?  
		getMenuTitle($option, $task, $Itemid, null, $shLangName) : $shSampleName;
$shSampleName = (empty($shSampleName) || $shSampleName == '/') ? 'SampleCom':$shSampleName;

switch ($task) {
	case 'task1':
	case 'task2' :
		$dosef = false;  // these tasks do not require SEF URL
		break;

	default:
		$title[] = $sh_LANG[$shLangIso]['_COM_SEF_SH_VIEW_SAMPLE'];
		// insert a 'View sample' string,
		// according to language
		// only if you have defined the
		if (!empty($sampleId)) {   // fetch some data about the content
			$q = 'SELECT id, title FROM #__samplenames WHERE id = '.$sampleId;
			// select clause includes id, even if
			$database->setQuery($q);    // we don't need it, in order for Joomfish to
			// return a translated version

			if (shTranslateUrl($option, $shLangName)) // V 1.2.4.m   // get it in the right language
				$database->loadObject( $sampleTitle);
			else $database->loadObject( $sampleTitle, false);
			// second param at false forces Joomfish to
			// return default language version instead of
			// current language

			if ($sampleTitle) {
				// if we found a title for this element
				$title[] = $sampleTitle->title;
				// insert it in URL array
				shRemoveFromGETVarsList('sampleId');
				// remove sampleId var from GET vars list
				// as we have found a text equivalent
			}
		}
		shRemoveFromGETVarsList('task');
	// also remove task, as it is not needed
	// because we can revert the SEF URL without it
}

// ------------------  standard plugin finalize function - don't change ---------------------------  
if ($dosef) {
	$string = shFinalizePlugin( $string, $title, $shAppendString, $shItemidString,
			(isset($limit) ? @$limit : null), (isset($limitstart) ? @$limitstart : null),
			(isset($shLangName) ? @$shLangName : null));
}      
// ------------------  standard plugin finalize function - don't change ---------------------------

?>
